/* moisture_sensor
 * 
 * This program checks the analog input (pin A0) coming from a moisture sensor
 * and switch on a speaker placed on the digital pin 13 if the read data is below a
 * certain threshold and increase frequency of swithcing if the read data keees dropping.
 * 
 *
 */


int sensorPin = A0;    // select the input pin for the sensor
int outPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(outPin, OUTPUT);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
  if(sensorValue>1000){
    digitalWrite(outPin, HIGH);  
     delay(sensorValue);   
  }
  else{
    
  // turn the ledPin on
  digitalWrite(outPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  // turn the ledPin off:        
  digitalWrite(outPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);  
  }  
   
}
